﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Worldme.YHChatSDK.Common.Constant.Enums
{
    public enum EventType
    {
        MESSAGE_RECEIVE_NORMAL,
        MESSAGE_RECEIVE_INSTRUCTION,
        BOT_FOLLOWED,
        BOT_UNFOLLOWED,
        GROUP_JOIN,
        GROUP_LEAVE,
        BUTTON_REPORT_INLINE,
        BOT_SHORTCUT_MENU
    }

    public static class EventTypeExtensions
    {
        private static readonly Dictionary<EventType, (string Code, string Desc)> _eventTypeMap = new Dictionary<EventType, (string, string)>
    {
        { EventType.MESSAGE_RECEIVE_NORMAL, ("message.receive.normal", "普通消息事件") },
        { EventType.MESSAGE_RECEIVE_INSTRUCTION, ("message.receive.instruction", "指令消息事件") },
        { EventType.BOT_FOLLOWED, ("bot.followed", "关注机器人事件") },
        { EventType.BOT_UNFOLLOWED, ("bot.unfollowed", "取消关注机器人事件") },
        { EventType.GROUP_JOIN, ("group.join", "用户加入群事件") },
        { EventType.GROUP_LEAVE, ("group.leave", "用户退出群事件") },
        { EventType.BUTTON_REPORT_INLINE, ("button.report.inline", "消息中按钮点击事件") },
        { EventType.BOT_SHORTCUT_MENU, ("bot.shortcut.menu", "聊天框上方菜单按钮事件") }
    };

        public static string GetCode(this EventType eventType)
        {
            if (_eventTypeMap.TryGetValue(eventType, out var info))
                return info.Code;
            return string.Empty;
        }

        // 获取描述
        public static string GetDesc(this EventType eventType)
        {
            if (_eventTypeMap.TryGetValue(eventType, out var info))
                return info.Desc;
            return string.Empty;
        }

        // 根据 code 获取描述
        public static string GetDesc(string code)
        {
            foreach (var kvp in _eventTypeMap)
            {
                if (kvp.Value.Code == code)
                    return kvp.Value.Desc;
            }
            return string.Empty;
        }

        // 检查是否存在某个 code
        public static bool HasCode(string code)
        {
            foreach (var kvp in _eventTypeMap)
            {
                if (kvp.Value.Code == code)
                    return true;
            }
            return false;
        }

        // 获取所有 code 的列表
        public static IReadOnlyList<string> GetAllCodes()
        {
            var codes = new List<string>();
            foreach (var kvp in _eventTypeMap)
            {
                codes.Add(kvp.Value.Code);
            }
            return codes.AsReadOnly();
        }

        // 获取所有描述的字典（code -> desc）
        public static IReadOnlyDictionary<string, string> GetAllCodeDescMap()
        {
            var map = new Dictionary<string, string>();
            foreach (var kvp in _eventTypeMap)
            {
                map[kvp.Key.ToString()] = kvp.Value.Desc; // 或者使用 kvp.Value.Code 作为 key，根据需求调整
            }
            // 如果希望以 code 作为 key：
            var codeDescMap = new Dictionary<string, string>();
            foreach (var kvp in _eventTypeMap)
            {
                codeDescMap[kvp.Value.Code] = kvp.Value.Desc;
            }
            return codeDescMap.AsReadOnly();
        }


    }
}
